package com.sale.system.dubbo;

import com.sale.common.core.domain.R;
import com.sale.common.core.utils.BeanCopyUtils;
import com.sale.system.api.RemoteStaffManagementService;
import com.sale.system.api.domain.dto.SysStaffManagementDto;
import com.sale.system.domain.PullDown;
import com.sale.system.domain.SysStaffManagement;
import com.sale.system.domain.dto.SysTheDropDto;
import com.sale.system.mapper.SysStaffManagementMapper;
import com.sale.system.service.ISysStaffManagementService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 职员管理
 */
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteStaffManagementServiceImpl implements RemoteStaffManagementService {

    private final ISysStaffManagementService sysStaffManagementService;

    private final SysStaffManagementMapper sysStaffManagementMapper;

    /**
     * 通过id获取职员数据
     * @param staffId
     * @return
     */
    @Override
    public R<SysStaffManagementDto> getInfo(Long staffId) {
        SysStaffManagementDto sysStaffManagementDto = new SysStaffManagementDto();
        SysStaffManagement staffManagementById = sysStaffManagementService.getStaffManagementById(staffId);
        BeanUtils.copyProperties(staffManagementById,sysStaffManagementDto);
        return R.ok(sysStaffManagementDto);
    }

    /**
     * 获取职员数据
     * @param
     * @return
     */
    @Override
    public Map<String, String> selectAllStaffManagement() {
        List<PullDown> list = sysStaffManagementMapper.selectAllStaffManagement();
        Map<String, String> map = list.stream().collect(Collectors.toMap(PullDown::getValue, PullDown::getLabel));
        return map;
    }

    /**
     * 根据职员名称 查询职员id
     * @param
     * @return
     */
    @Override
    public Long selectStaffManagementName(String staffName) {
        return sysStaffManagementMapper.selectStaffManagementName(staffName);
    }
}
